import React, { Component } from 'react';
import { connect } from 'dva';
import Link from 'umi/link';
import { Row, Col, Button, Form, Input, Checkbox, Alert, Icon } from 'antd';
import styles from './Forget.less';

@connect(({register, loading})=>({
  register,
  submitting: loading.effects['register/submit'],
}))
@Form.create()
class ForgetPage extends Component{

  handleSubmit = e=>{
    e.preventDefault();

    const {form} = this.props;
    form.validateFields((err, values)=>{
      if(!err){
        const { dispatch } = this.props;
        dispatch({
          type: 'register/submit',
          payload: {
            ...values,
          },
        });
      }
    })
  }

  render(){
    const { register, submitting, form } = this.props;

    return (
      <div className={styles.main}>
        <Form onSubmit={this.handleSubmit.bind(this)}>
          <Form.Item>
            {
              form.getFieldDecorator('email', {
                rules: [{required: true, message: '请输入邮箱'}]
              })(
                <Input prefix={<Icon type={'mail'} className={styles.input}></Icon>} placeholder='邮箱'/>
              )
            }
          </Form.Item>
          <Form.Item>
            {
              form.getFieldDecorator('password', {
                rules: [{required: true, message: '请输入密码'}]
              })(
                <Input type='password' prefix={<Icon type={'lock'} className={styles.input}></Icon>} placeholder='密码'/>
              )
            }
          </Form.Item>
          <Form.Item>
            <Button
              className={styles.btnSubmit}
              loading={submitting}
              type='primary'
              htmlType='submit'
              onClick={this.handleSubmit.bind(this)}>注册</Button>
          </Form.Item>
        </Form>
      </div>
    )
  }
}

export default ForgetPage;
